<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * Constructs a new bound constraint. Before the constraint can be used, the
<span class='line'>  3</span>  * {@link #x} and {@link #y} methods must be call to specify the bounds.
<span class='line'>  4</span>  *
<span class='line'>  5</span>  * @class Constrains particles to within fixed rectangular bounds. For example,
<span class='line'>  6</span>  * this constraint can be used to constrain particles in a physics simulation
<span class='line'>  7</span>  * within the bounds of an enclosing panel.
<span class='line'>  8</span>  *
<span class='line'>  9</span>  * &lt;p>Note that the current implementation treats particles as points, with no
<span class='line'> 10</span>  * area. If the particles are rendered as dots, be sure to include some
<span class='line'> 11</span>  * additional padding to inset the bounds such that the edges of the dots do not
<span class='line'> 12</span>  * get clipped by the panel bounds. If the particles have different radii, this
<span class='line'> 13</span>  * constraint would need to be extended using a radius function, similar to
<span class='line'> 14</span>  * {@link pv.Constraint.collision}.
<span class='line'> 15</span>  *
<span class='line'> 16</span>  * @see pv.Layout.Force
<span class='line'> 17</span>  * @extends pv.Constraint
<span class='line'> 18</span>  */</span><span class="WHIT">
<span class='line'> 19</span> </span><span class="NAME">pv.Constraint.bound</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">constraint</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="WHIT">      </span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="WHIT">      </span><span class="NAME">y</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 23</span> 
<span class='line'> 24</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 25</span>    * Sets or gets the bounds on the x-coordinate.
<span class='line'> 26</span>    *
<span class='line'> 27</span>    * @function
<span class='line'> 28</span>    * @name pv.Constraint.bound.prototype.x
<span class='line'> 29</span>    * @param {number} min the minimum allowed x-coordinate.
<span class='line'> 30</span>    * @param {number} max the maximum allowed x-coordinate.
<span class='line'> 31</span>    * @returns {pv.Constraint.bound} this.
<span class='line'> 32</span>    */</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT">  </span><span class="NAME">constraint.x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">      </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="NAME">min</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Math.min</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Math.max</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 37</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 38</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 39</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 40</span> 
<span class='line'> 41</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 42</span>    * Sets or gets the bounds on the y-coordinate.
<span class='line'> 43</span>    *
<span class='line'> 44</span>    * @function
<span class='line'> 45</span>    * @name pv.Constraint.bound.prototype.y
<span class='line'> 46</span>    * @param {number} min the minimum allowed y-coordinate.
<span class='line'> 47</span>    * @param {number} max the maximum allowed y-coordinate.
<span class='line'> 48</span>    * @returns {pv.Constraint.bound} this.
<span class='line'> 49</span>    */</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">  </span><span class="NAME">constraint.y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">arguments.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">      </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="NAME">min</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Math.min</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Math.max</span><span class="PUNC">(</span><span class="NAME">min</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">max</span><span class="PUNC">)</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">      </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 57</span> 
<span class='line'> 58</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 59</span>    * Applies this constraint to the specified particles.
<span class='line'> 60</span>    *
<span class='line'> 61</span>    * @function
<span class='line'> 62</span>    * @name pv.Constraint.bound.prototype.apply
<span class='line'> 63</span>    * @param {pv.Particle} particles particles to which to apply this constraint.
<span class='line'> 64</span>    */</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">  </span><span class="NAME">constraint.apply</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">particles</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">particles</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">p.next</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">      </span><span class="NAME">p.x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">p.x</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">x.min</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">x.min</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">p.x</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">x.max</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">x.max</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">p.x</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">y</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">particles</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">p.next</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">      </span><span class="NAME">p.y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">p.y</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">y.min</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">y.min</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">p.y</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">y.max</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">y.max</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">p.y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 73</span> 
<span class='line'> 74</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">constraint</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 76</span> </span></pre></body></html>